package com.nlp.trie.experiment1;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Assess {
	/**
	 * 获得s1和s2分词的相似分数0-100分
	 * @param s1
	 * @param s2
	 * @return
	 */
	public static int get(String s1, String s2) {
		Map<Integer, Integer> map1 = get(s1);
		Map<Integer, Integer> map2 = get(s2);
		int goal = 0;
		for(Entry<Integer, Integer> e1 : map1.entrySet()) {
			int key = e1.getKey();
			int value = e1.getValue();
			if (map2.get(key).equals(value)) {
				goal++;
			}
		}
		
		return goal*100/map1.size();
	}

	/**
	 * 获得分词序列号
	 * @param s
	 * @return
	 */
	private static Map<Integer, Integer> get(String s) {
		int start = 0;
		int num = 0;
		Map<Integer, Integer> map = new HashMap<>();
		while(start < s.length()) {
			int end = s.indexOf("'", start+1);
			if (end == -1) {
				end = s.length();
			}
			map.put(start-num, end-num);
			num++;
			start = end+1;
		}
		
		return map;
	}

}
